<?

require_once(dirname(__FILE__) . '/../bootstrap.php');
/*
class tests_controller {
			
	public static function test_1() {

		header('Content-Type: text/plain; charset=utf-8', true);
		echo "Hello World!\n";
	}
}

$action = preg_replace('/\-/', '_', bf::$request->get('action'));
if (in_array($action, get_class_methods('tests_controller'))) {
    tests_controller::$action();
}
*/

class controller_tests extends bf_controller_base {
			
	public function test_1() {

		header('Content-Type: text/plain; charset=utf-8', true);
		$name = $this->get(array('name' => 'World'));
		echo "Hello {$name}!\n";
	}

	public function test_2() {
		bf::view('welcome');
	}

	public function test_3() {
		var_dump($this->session->get('mark'));
		$this->session->set('mark', 5);
	}

	public function test_4() {

		header('Content-Type: text/plain; charset=utf-8', true);		

		echo "creating database\n";

		$db_path = dirname(__FILE__) . '/../data/database.sqlite'; // just for example

		bf::$application->runtime->db = new bf_db_sqlite3(array(
			'database' => $db_path,
			'log' => dirname(__FILE__) . '/../logs/db-sqlite3-' . date('Y-m-d') . '.log',
			'logging' => 2,
		));

		var_dump(bf::$application->runtime->db);

		bf::$application->runtime->db->query('create table t1 (a int, b int)');
		bf::$application->runtime->db->query('insert into t1 (a, b) values ($1, $2)', array(1, 1000));
		bf::$application->runtime->db->query('insert into t1 (a, b) values ($1, $2)', array(2, 2000));
		bf::$application->runtime->db->query('insert into t1 (a, b) values ($1, $2)', array(3, 4000));
		bf::$application->runtime->db->query('insert into t1 (a, b) values ($1, $2)', array(4, 8000));

//		var_dump(bf::$application->runtime->db->query_all('select * from t1'));
//		var_dump(bf::$application->runtime->db->query_column('select b from t1 where a = 3 limit 1'));
//		var_dump(bf::$application->runtime->db->query_all_obj('select * from t1 where a = 3 limit 1'));

		$t1 = new model_test1();
		var_dump($t1->get(4));
		var_dump($t1->count());
		var_dump($t1->select(array(), 1));

		bf::$application->runtime->db->disconnect();
		unlink($db_path);

	}
}

?>